package com.test;

import java.net.InetAddress;
import java.net.NetworkInterface;

/******************************************************************************
 * @discribe:                                                               *
 * @project : skyform-api                                                    *
 * @author  : najianlin                                                      *
 * @crtDate : 2014-11-20 上午10:52:39                                           *
 * @email   : najl@chinaskycloud.com                                         *
 * @version : 3.1.0                                                          *
 *****************************************************************************/
public class SystemUtil {

    public static String getMacAddress() {
        InetAddress ip;
        try {

            ip = InetAddress.getLocalHost();

            NetworkInterface network = NetworkInterface.getByInetAddress(ip);

            byte[] mac = network.getHardwareAddress();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mac.length; i++) {
                sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
                break;
            }

            return sb.toString();

        } catch(Exception e) {
        	e.printStackTrace();
            return null;
        }
    }

    public static void main(String ...args) {
        System.out.println(getMacAddress());
    }
}